Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Google Sheets "Success Handler" Output to Variable

I'm pretty new to writing code and have been playing around with Google Sheets to try to get some basic interaction between some data I have in my sheet and a user interface using HTML. The idea is that I have data in my google sheet that I want to turn into a bar chart in HTML.

In my Sheets I have a column of data that has some values for each month in the format:
July 0
August 32
September 1261
October 0
etc...

In my Code.gs file I have a function that returns this as a list:

//Returns the corresponding yearly waste value for input month. Used for chart.
  function getYearlyWaste() {
    var yearlyWaste = spreadsheet.getRange(2, 28, 12).getValues();
    return yearlyWaste;
  }

When I run this in the Index.html:

google.script.run.withSuccessHandler(wasteVals).getYearlyWaste();

I want to be able to output the getYearlyWaste() function to a variable to use to draw a chart:

function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Month', 'Waste', 'Recycling'],
          ['Jan', yearlyWaste[0], yearlyRecycling[0]],
          ['Feb', yearlyWaste[1], yearlyRecycling[1]],
          ['Mar', yearlyWaste[2], yearlyRecycling[2]],
          ['Apr', yearlyWaste[3], yearlyRecycling[3]],
          ['May', yearlyWaste[4], yearlyRecycling[4]],
          ['Jun', yearlyWaste[5], yearlyRecycling[5]],
          ['Jul', yearlyWaste[6], yearlyRecycling[6]],
          ['Aug', yearlyWaste[7], yearlyRecycling[7]],
          ['Sep', yearlyWaste[8], yearlyRecycling[8]],
          ['Oct', yearlyWaste[9], yearlyRecycling[9]],
          ['Nov', yearlyWaste[10], yearlyRecycling[10]],
          ['Dec', yearlyWaste[11], yearlyRecycling[11]]
        ]);

However no matter what I do, I just get undefined. I feel like I'm missing something small, so any help would be appreciated.

As a note, I have tried pulling back individual values from the sheet and assigning them to an element ID value to be sure that the function is working right and I get the expected result.

Thanks in advance :)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda